package com.canbot.u05.activity.presidemode.newcode;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import com.canbot.u05.R;
import com.canbot.u05.socket.MsgSendUtils;
import com.canbot.u05.socket.MsgType;
import com.canbot.u05.utils.ToastTools;
import com.canbot.u05.widget.LoadingDialogUtils;

import java.io.Serializable;

import butterknife.ButterKnife;
import butterknife.Unbinder;

public abstract class BaseHostActivity extends Activity {
    protected static boolean isDebug = false;
    protected static final int REQUEST_ADD = 1;
    protected static final int REQUEST_EDIT = 2;
    protected static final int REQUEST_CTEATE_TYPE = 3;
    protected static final int REQUEST_PERMISSION = 4;
    protected static final int REQUEST_WORK_POS = 5;
    protected static final int REQUEST_WORK_DAY = 6;
    protected static final int REQUEST_PWD = 7;
    protected static final int REQUEST_DANCE = 8; // 舞蹈表演
    protected static final int REQUEST_VIDEO = 9; // 视频播放
    protected static final int REQUEST_GBYD = 10; // 贵宾引导
    protected static final int REQUEST_CXLK = 11; // 促销揽客
    protected static final int REQUEST_MUSIC = 12; // 音乐播放
    protected static final int REQUEST_YBJD = 13; // 迎宾接待
    protected static final int REQUEST_HBXC = 14; // 海报宣传
    protected static final int REQUEST_WORK_DAY_CHOICE = 15;
    protected static final String DATA = "data";
    protected static final String KEY_REQUESTCODE = "requestCode";
    private Unbinder unbinder;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //hideBottomUIMenu();
        setContentView(getLayoutResId());
        unbinder = ButterKnife.bind(this);
        initEventData();
    }

    /**
     * 隐藏虚拟按键，并且全屏
     */
    protected void hideBottomUIMenu() {
        View decorView = getWindow().getDecorView();
        int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN;
        decorView.setSystemUiVisibility(uiOptions);
    }

    protected abstract void initEventData();

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (unbinder != null) {
            unbinder.unbind();
        }
    }

    private static final String TAG = "BaseHostActivity";

    protected void gotoActivity(Class cls) {
        startActivity(new Intent(this, cls));
        overridePendingTransition(R.anim.face_zoom_enter, R.anim.face_zoom_exit);
    }

    protected void gotoActivityForResult(Class cls, int requestCode, Serializable data) {
        Intent intent = new Intent(this, cls);
        intent.putExtra(DATA, data);
        intent.putExtra(KEY_REQUESTCODE, requestCode);
        startActivityForResult(intent, requestCode);
        overridePendingTransition(R.anim.face_zoom_enter, R.anim.face_zoom_exit);
    }

    protected void gotoActivityForResult(Class cls, int requestCode) {
        Intent intent = new Intent(this, cls);
        startActivityForResult(intent, requestCode);
        overridePendingTransition(R.anim.face_zoom_enter, R.anim.face_zoom_exit);
    }

    protected void gotoActivityForResult(Intent intent, int requestCode) {
        startActivityForResult(intent, requestCode);
        overridePendingTransition(R.anim.face_zoom_enter, R.anim.face_zoom_exit);
    }

    protected void gotoActivity(Intent intent) {
        startActivity(intent);
        overridePendingTransition(R.anim.face_zoom_enter, R.anim.face_zoom_exit);
    }

    private Dialog dialog;

    protected void showLoadingDialog(String msg) {
        dialog = LoadingDialogUtils.createLoadingDialog(this, msg);
        dialog.show();
    }

    protected void dismissDialog() {
        if (dialog != null && dialog.isShowing()) {
            dialog.dismiss();
        }
    }

    /**
     * 随机播放音频
     *
     * @param voices
     */
    protected void playRandomVoiceWithEmotion(String[][] voices) {
        int index = (int) (Math.random() * voices.length);
        String[] voiceWithEmotion = voices[index];
        MsgSendUtils.sendStringMsg(MsgType.PLAY_SOUND, voiceWithEmotion[0]);
        playEyeEmotion(voiceWithEmotion[1]);
    }

    /**
     * 播放眼睛表情
     *
     * @param eyeId
     */
    protected void playEyeEmotion(String eyeId) {
        MsgSendUtils.sendStringMsg(MsgType.EYE_MOTION, eyeId);
    }

    protected void showToast(String msg) {
        ToastTools.newInstance(this).showText(msg);
    }

    protected abstract int getLayoutResId();
}
